﻿Imports System.Data.SqlClient

Public Class RepriseC

    Private user As String
    Private userSite As String
    Private cn As CnData
    Private da As SqlDataAdapter
    Private ds As DataSet
    Private cmd As SqlCommand
    Private dtr As SqlDataReader

    Public Sub New(ByVal user As String, ByRef cn As CnData, ByVal userSite As String)
        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        Me.user = user
        Me.cn = cn
        Me.userSite = userSite

    End Sub



    Private Sub RepriseC_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cn.Open()
        da = New SqlDataAdapter(" SELECT     Chargements.Chargement, Sites.nomDoc AS Destinataire, Chargements.NbAgres AS [Nb d'agrès], Chargements.Plomb1, Chargements.Plomb2, " _
                    & " Chargements.Transporteur, Chargements.Immatriculation, Chargements.Chauffeur " _
                    & " FROM         Chargements LEFT OUTER JOIN " _
                    & " Sites ON Chargements.Destinataire = Sites.NumSite  WHERE     (Chargements.Expediteur = '" & userSite & "' AND Chargements.DateExp IS NULL)", cn.getCn)

        ds = New DataSet
        da.Fill(ds, "Liste")
        Liste.DataSource = ds.Tables("Liste")

        cn.Close()
    End Sub


    Private Sub Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fermer.Click
        Me.Close()
    End Sub

    Private Sub Liste_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Liste.CellContentDoubleClick
        If e.RowIndex < 0 Then Exit Sub
        Dim ChildForm As New Expedition(user, cn, Liste.Item(0, e.RowIndex).Value.ToString, True)
        If ChildForm.ShowDialog() = Windows.Forms.DialogResult.OK Then Me.Close()
    End Sub

    Private Sub Liste_RowHeaderMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Liste.RowHeaderMouseDoubleClick
        If e.RowIndex < 0 Then Exit Sub
        If MsgBox("Voulez vous supprimer le chargement '" & Liste.Item(0, e.RowIndex).Value.ToString & "' ?", MsgBoxStyle.YesNo) = vbYes Then
            cn.Open()
            cmd = New SqlCommand("DELETE FROM Chargements WHERE chargement='" & Liste.Item(0, e.RowIndex).Value.ToString & "'", cn.getCn())
            cmd.ExecuteNonQuery()
            cmd = New SqlCommand("DELETE FROM BrouillonC WHERE chargement='" & Liste.Item(0, e.RowIndex).Value.ToString & "'", cn.getCn())
            cmd.ExecuteNonQuery()
            da = New SqlDataAdapter(" SELECT     Chargements.Chargement, Sites.nomDoc AS Destinataire, Chargements.NbAgres AS [Nb d'agrès], Chargements.Plomb1, Chargements.Plomb2, " _
                    & " Chargements.Transporteur, Chargements.Immatriculation, Chargements.Chauffeur " _
                    & " FROM         Chargements LEFT OUTER JOIN " _
                    & " Sites ON Chargements.Destinataire = Sites.NumSite  WHERE     (Chargements.Expediteur = '" & userSite & "' AND Chargements.DateExp IS NULL)", cn.getCn)

            'ds = New DataSet
            ds.Tables("Liste").Clear()
            da.Fill(ds, "Liste")
            cn.Close()
        End If
    End Sub

End Class